// const buff1 = Buffer.alloc(10)
// console.log(buff1)

// const buff2 = Buffer.allocUnsafe(10)
// console.log(buff2)

// const buff3 = Buffer.from([1, 2, 3, 255])
// console.log(buff3)

// const buff4 = Buffer.from('hello world', 'utf8')
// let buffBase64 = buff4.toString('base64')
// console.log(buffBase64)
// console.log(buff4)

// const buff5 = Buffer.from('hello world', 'latin1')
// console.log(buff5)

// const buff6 = Buffer.from([255, 320, 32, 1])
// console.log(buff6)
// const uint8Arr = new Uint8Array(buff6)
// console.log(uint8Arr)

// const arr = new Uint16Array(2)
// arr[0] = 4000
// arr[1] = 5000
// console.log(arr.buffer)  // ArrayBuffer { [Uint8Contents]: <a0 0f 88 13>, byteLength: 4 }
// const buff7 = Buffer.from(arr)
// console.log(buff7) // <Buffer a0 88>
// const buff8 = Buffer.from(arr.buffer)
// console.log(buff8) // <Buffer a0 0f 88 13>
// arr[1] = 255
// console.log(buff7) // <Buffer a0 88>
// console.log(buff8) // <Buffer a0 0f ff 00>

const result = Buffer.from('hsajdhfasfkiuewrihjkdhfxzmnjdhfksa')

// const buff9 = Buffer.from(arr1.buffer)
// console.log(buff9.toString())
function decToBinary (num, binary = 2) {
    let binaryRes = [], res = Math.floor(num / binary), mod = num % binary, hex = ['A', 'B', 'C', 'D', 'E', 'F'];
    while (true) {
        binaryRes.unshift(binary == 16 && mod >= 10 ? hex[mod - 10] : mod)
        if (res < binary) {
            binaryRes.unshift(binary == 16 && res >= 10 ? hex[res - 10] : res)
            return binaryRes.join('')
        }
        mod = res % binary
        res = Math.floor(res / binary)
    }
}

function binaryTo (num, binary) {
    let strNum = String(num), symbol = { A: 10, B: 11, C: 12, D: 13, E: 14, F: 15 }, n, dec = 0;
    for (let i = strNum.length - 1; i >= 0; i--) {
        n = isNaN(strNum[i]) ? symbol[strNum[i]] : Number(strNum[i])
        dec += n * Math.pow(binary, strNum.length - 1 - i)
    }
    return dec
}


console.log(decToBinary('13800138000', 2)) //1100110110100011010110010100010000
console.log(decToBinary('13800138000', 8)) //146643262420
console.log(decToBinary('13800138000', 16)) //3368D6510

console.log(binaryTo('1100110110100011010110010100010000', 2))
console.log(binaryTo('146643262420', 8))
console.log(binaryTo('3368D6510', 16))